home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2001 June
/
CHIP Haziran 2001.iso
/
prog
/
haziran
/
19
/
setup.exe
/
data.z
/
pp_lib.bas
< prev
next >
Wrap
BASIC Source File
|
2001-04-11
|
4KB
|
137 lines
Attribute VB_Name = "pp_lib"
'
' File - pp_lib.bas
'
' This application reads and writes data to the Parallel Port, and is
' controlled via a graphical user interface - pp_gui.frm
' The Parallel Port is accessed directly on the motherboard, using
' WinDriver functions.
'
Option Explicit
' Internal data structures
Type PP_HANDLE
hWD As Long
cardReg As WD_CARD_REGISTER
base_addr As Long
End Type
' PP register definitions
Global Const PP_data_OFFSET = &H0
Global Const PP_status_OFFSET = &H1
Global Const PP_control_OFFSET = &H2
Global g_Data As Byte
Sub PP_SetCardElements(hPP As PP_HANDLE, base_addr As Long)
Dim pItem As WD_ITEMS
hPP.cardReg.Card.dwItems = 1
hPP.cardReg.Card.Item(0).Item = ITEM_IO
hPP.cardReg.Card.Item(0).fNotSharable = False
hPP.cardReg.Card.Item(0).dw1 = base_addr
hPP.cardReg.Card.Item(0).dw2 = 8
hPP.base_addr = base_addr
End Sub
Function PP_Open(hPP As PP_HANDLE, base_addr As Long) As Boolean
Dim ver As WD_Version
hPP.cardReg.hCard = 0
hPP.hWD = INVALID_HANDLE_VALUE
hPP.hWD = WD_Open()
' Check if handle valid & version OK
If (hPP.hWD = INVALID_HANDLE_VALUE) Then
MsgBox "Failed opening WinDriver device", vbCritical + vbOKOnly, "parallel_port"
GoTo exitError
End If
WD_Version hPP.hWD, ver
If (ver.dwVer < WD_VER) Then
MsgBox "Incorrect WinDriver version", vbCritical + vbOKOnly, "parallel_port"
GoTo exitError
End If
PP_SetCardElements hPP, base_addr
hPP.cardReg.fCheckLockOnly = False
WD_CardRegister hPP.hWD, hPP.cardReg
If (hPP.cardReg.hCard = 0) Then
MsgBox "Failed locking device.", vbCritical + vbOKOnly, "parallel_port"
GoTo exitError
End If
' Open finished OK
PP_Open = True
GoTo finish
exitError:
' Error during Open
If (hPP.cardReg.hCard <> 0) Then
WD_CardUnregister hPP.hWD, hPP.cardReg
End If
If (hPP.hWD <> INVALID_HANDLE_VALUE) Then
WD_Close hPP.hWD
End If
hPP.base_addr = 0
PP_Open = False
finish:
End Function
Sub PP_Close(hPP As PP_HANDLE)
' Unregister card
If (hPP.cardReg.hCard) Then
WD_CardUnregister hPP.hWD, hPP.cardReg
End If
' Close WinDriver
WD_Close hPP.hWD
End Sub
Function PP_ReadByte(hPP As PP_HANDLE, dwOffset As Long) As Byte
Dim Trans As WD_Transfer
Trans.dwPort = hPP.base_addr + dwOffset
Trans.cmdTrans = RP_BYTE
WD_Transfer hPP.hWD, Trans
PP_ReadByte = Trans.dwDataTransfer
End Function
Sub PP_WriteByte(hPP As PP_HANDLE, dwOffset As Long, Data As Byte)
Dim Trans As WD_Transfer
Trans.dwPort = hPP.base_addr + dwOffset
Trans.dwDataTransfer = Data
Trans.cmdTrans = WP_BYTE
Trans.dwDataTransfer = Data
WD_Transfer hPP.hWD, Trans
End Sub
Function PP_ReadData(hPP As PP_HANDLE) As Byte
PP_ReadData = PP_ReadByte(hPP, PP_data_OFFSET)
End Function
Sub PP_WriteData(hPP As PP_HANDLE, Data As Byte)
PP_WriteByte hPP, PP_data_OFFSET, Data
End Sub
Function PP_ReadStatus(hPP As PP_HANDLE) As Byte
PP_ReadStatus = PP_ReadByte(hPP, PP_status_OFFSET)
End Function
Sub PP_WriteStatus(hPP As PP_HANDLE, Data As Byte)
PP_WriteByte hPP, PP_status_OFFSET, Data
End Sub
Function PP_ReadControl(hPP As PP_HANDLE) As Byte
PP_ReadControl = PP_ReadByte(hPP, PP_control_OFFSET)
End Function
Sub PP_WriteControl(hPP As PP_HANDLE, Data As Byte)
PP_WriteByte hPP, PP_control_OFFSET, Data
End Sub